<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
    <form action="" method="POST">
        <div>
            <label for="user">用户名</label>
            <input type="text" id="user" placeholder="请输入用户名" value="Abc">
        </div>
        <div>
            <label for="pwd">密码</label>
            <input type="password" id="pwd">
        </div>
        <div>
            <label for="gender">性别</label>
            <label for="male">男</label>
            <input type="radio" id="male" name="gender" value="男">
            <label for="female">女</label>
            <input type="radio" id="female" name="gender" value="女">

        </div>

    </form>
    <script>
        // 1.找到input#user
        var userIpt = document.querySelector('#user');
        var username = userIpt.value;

        console.log(username)
        userIpt.value = "赵德玺"
        var fipt = document.getElementById('female')
        //通过checked判断是否选中
        fipt.checked
        // 打印被选中的元素的value
        function show(){
            var g = document.querySelector("input[name=gender]:checked")
            console.log(g.value)
        }
        // 打印被选中的元素的value,方法2
        function show2(){
            var gs = document.querySelectorAll("input[name=gender]");
            for(var i=0; i<gs.length; i++){
                var g = gs[i]
                if(g.checked){
                    console.log(g.value)
                }
            }
        }
    </script>
</body>

</html>